<?php

namespace App\Dao\Settings;

use Yj\Daos\BaseDao;
use App\Model\Settings\SettingsTaskRefresh;
use Hyperf\Database\Model\Builder;
use Yj\Daos\Verify;
use Hyperf\Utils\Collection;

/**
 * @var SettingsTaskRefresh
 */
class SettingsTaskRefreshDao extends BaseDao
{
    public function DaoWhere(array $params)
    {

        return $this->getDaoQuery($params, function (Verify $verify) {
            $verify("id", function (Builder $query, $id) {
                $query->where("id", $id);
            });
        });

    }

    public function lists(Collection $params)
    {
        $data = $this->DaoWhere($params->toArray())->orderByDesc("id")->getList();
        return $data;
    }

    public function add(Collection $params)
    {
        $data = $this->create($params->toArray());
        return $data;
    }

    public function edit(int $id, Collection $params)
    {
        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        $data->fill($params->toArray());
        return $data->save();
    }

    public function del(int $id)
    {
        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        return $data->delete();
    }
}
